'''自选一片报告或演讲稿，利用jieba分析出器词频排前5的关键词。'''
import jieba
f = open('六中全会公报.txt','r',encoding='utf-8')
txt = f.read()
f.close()
words = jieba.lcut(txt)
excludes = {'，', '的', '、', '和', '了', '。', '\n'}
counts = {}
for word in words:
    counts[word] = counts.get(word,0) + 1
for word in excludes:
    del(counts[word])
items = list(counts.items())
items.sort(key=lambda x:x[1],reverse=True)
for i in range(5):
    word,count = items[i]
    print('{0:<10}{1:>5}'.format(word,count))
